Test Series - java script

Test Number 10/92

Q: The function definitions in JavaScript begins with _____________
A. Identifier and Parentheses
B. Return type and Identifier
C. Return type, Function keyword, Identifier and Parentheses
D. Identifier and Return type
Solution: The function definitions begin with the keyword function followed by an identifier that names the function and a pair of parentheses around a comma-separated list of zero or more identifiers.
Q: When does the function name become optional in JavaScript?
A. When the function is defined as a looping statement
B. When the function is defined as expressions
C. When the function is predefined
D. when the function is called
Solution: The function name is optional for functions defined as expressions. A function declaration statement actually declares a variable and assigns a function object to it.
Q: What is the purpose of a return statement in a function?
A. Returns the value and continues executing rest of the statements, if any
B. Returns the value and stops the program
C. Returns the value and stops executing the function
D. Stops executing the function and returns the value
Solution: The return stops the execution of the function when it is encountered within the function. It returns the value to the statement where the function is called.
Q: What will happen if a return statement does not have an associated expression?
A. It returns the value 0
B. It will throw an exception
C. It returns the undefined value
D. It will throw an error
Solution: A function without a return statement will return a default value. If the return statement does not have an associated expression then it returns an undefined value.
Q: A function with no return value is called ___________
A. Procedures
B. Method
C. Static function
D. Dynamic function
Solution: Void functions does not return a value. Functions with no return value are sometimes called procedures.
Q: The function stops its execution when it encounters?
A. continue statement
B. break statement
C. goto statement
D. return statement
Solution: Continue statement and break statement are used in the loops for skipping the iteration or going out of the loop. Whenever a return statement is encountered the function execution is stopped.
Q: Which keyword is used to define the function in javascript?
A. void
B. int
C. function
D. main
Solution: A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses(). Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).
Q: Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?
A. o(x,y);
B. o.m(x) && o.m(y);
C. m(x,y);
D. o.m(x,y);
Solution: The two argument in a function are separated by a comma (,). The code above is an invocation expression: it includes a function expression o.m and two argument expressions, x and y.
Q: What will be the output of the following JavaScript code?

     var pow=new Function("num1","num2","return Math.pow(num1,num2)");  
     document.writeln(pow(2,3));
A. error
B. 2
C. 3
D. 8
Solution: pow function is a predefined function which is present in the math library of javascript. The pow function accepts two arguments of which power of the first argument is calculated with respect to the second.
Q: What will be the output of the following JavaScript code?

var arr = [7, 5, 9, 1];  
var value = Math.max.apply(null, arr);  
document.writeln(value);
A. 7
B. 8
C. 1
D. 9
Solution: apply() is a predefined function method in javascript. The argument of apply() method contains elements of an array. It contains two values as argument which are optional as input.

You Have Score    /10